﻿using Shop.ProductService.Entities;
using Shop.ProductService.Repositorys;
using Shop.ProductService.Services.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.DependencyInjection;

namespace Shop.ProductService.Services
{

    /// <summary>
    /// 商品数据服务类
    /// </summary>
    [Dependency(ServiceLifetime.Singleton)]
    public class ProductService : CrudAppService<Products, ProductDto, Guid>, IProductService
    {

        public IProductRepository repository;

        public ProductService(IProductRepository repository) : base(repository)
        {
            this.repository = repository;
        }

        public async Task<List<ProductDto>> GetProductsAsync()
        {
            List<Products> products = repository.GetListAsync().Result;
            var result = products.Select(it => new ProductDto
            {
                Id = it.Id,
                ProductCode = it.ProductCode,
                ProductUrl = it.ProductUrl,
                ProductDescription = it.ProductDescription,
                ProductPrice = it.ProductPrice,
                ProductSold = it.ProductSold,
                ProductSort = it.ProductSort,
                ProductStatus = it.ProductStatus,
                ProductStock = it.ProductStock,
            }).ToList();
            return await Task.FromResult(result);
        }
    }
}
